<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Authentication extends CI_Controller {
	public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        $this->load->library('form_validation');
    }

	public function login()
	{
		$data['seo']['title'] = "Đăng nhập vào hệ thống";
		//$data['seo']['keyword'] = "";
		//$data['seo']['description'] = "";
		if($this->input->post('login')){
			$_POST = $this->input->post('data');
			$data['data']['_post'] = $_POST; 

			$this->form_validation->set_error_delimiters('<li>', '</li>');
			$this->form_validation->set_rules('data[username]', 'Tên tài khoản', 'trim|required|min_length[3]|max_length[20]|regex_match[/^([a-z0-9_])+$/i]');
			$this->form_validation->set_rules('data[password]', 'Mật khẩu', 'trim|required');
			if ($this->form_validation->run() == TRUE)
			{

			}
		}

		$this->load->view('backend/authentication/login', $data);
	}

	public function forgot()
	{
		$data['seo']['title'] = "Quên mật khẩu";
		$this->load->view('backend/authentication/forgot', $data);
	}

	public function create_manager()
	{
		$data['seo']['title'] = "Tạo tài khoản quản trị";
		if($this->input->post('create')){
			$_POST = $this->input->post('data');
			$data['data']['_post'] = $_POST; 

			$this->form_validation->set_error_delimiters('<li>', '</li>');
			$this->form_validation->set_rules('data[username]', 'Tên tài khoản', 'trim|required|min_length[3]|max_length[20]|regex_match[/^([a-z0-9_])+$/i]');
			$this->form_validation->set_rules('data[password]', 'Mật khẩu', 'trim|required');
			$this->form_validation->set_rules('data[email]', 'Email', 'trim|required|valid_email');
			if ($this->form_validation->run() == TRUE)
			{
				echo 'ok';
			}
		}

		$this->load->view('backend/authentication/create_manager', $data);
	}
}

